<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><link rel="stylesheet" type="text/css" href="style.css" /><script type="text/javascript" src="highlight.js"></script></head><body><pre><span class="hs-comment">-----------------------------------------------------------------------------</span><span>
</span><span id="line-2"></span><span class="hs-comment">-- |</span><span>
</span><span id="line-3"></span><span class="hs-comment">-- Module      :  GHC.ExecutionStack</span><span>
</span><span id="line-4"></span><span class="hs-comment">-- Copyright   :  (c) The University of Glasgow 2013-2015</span><span>
</span><span id="line-5"></span><span class="hs-comment">-- License     :  see libraries/base/LICENSE</span><span>
</span><span id="line-6"></span><span class="hs-comment">--</span><span>
</span><span id="line-7"></span><span class="hs-comment">-- Maintainer  :  cvs-ghc@haskell.org</span><span>
</span><span id="line-8"></span><span class="hs-comment">-- Stability   :  internal</span><span>
</span><span id="line-9"></span><span class="hs-comment">-- Portability :  non-portable (GHC Extensions)</span><span>
</span><span id="line-10"></span><span class="hs-comment">--</span><span>
</span><span id="line-11"></span><span class="hs-comment">-- This is a module for efficient stack traces. This stack trace implementation</span><span>
</span><span id="line-12"></span><span class="hs-comment">-- is considered low overhead. Basic usage looks like this:</span><span>
</span><span id="line-13"></span><span class="hs-comment">--</span><span>
</span><span id="line-14"></span><span class="hs-comment">-- @</span><span>
</span><span id="line-15"></span><span class="hs-comment">-- import GHC.ExecutionStack</span><span>
</span><span id="line-16"></span><span class="hs-comment">--</span><span>
</span><span id="line-17"></span><span class="hs-comment">-- myFunction :: IO ()</span><span>
</span><span id="line-18"></span><span class="hs-comment">-- myFunction = do</span><span>
</span><span id="line-19"></span><span class="hs-comment">--      putStrLn =&lt;&lt; showStackTrace</span><span>
</span><span id="line-20"></span><span class="hs-comment">-- @</span><span>
</span><span id="line-21"></span><span class="hs-comment">--</span><span>
</span><span id="line-22"></span><span class="hs-comment">-- Your GHC must have been built with @libdw@ support for this to work.</span><span>
</span><span id="line-23"></span><span class="hs-comment">--</span><span>
</span><span id="line-24"></span><span class="hs-comment">-- @</span><span>
</span><span id="line-25"></span><span class="hs-comment">-- user@host:~$ ghc --info | grep libdw</span><span>
</span><span id="line-26"></span><span class="hs-comment">--  ,(&quot;RTS expects libdw&quot;,&quot;YES&quot;)</span><span>
</span><span id="line-27"></span><span class="hs-comment">-- @</span><span>
</span><span id="line-28"></span><span class="hs-comment">--</span><span>
</span><span id="line-29"></span><span class="hs-comment">-- @since 4.9.0.0</span><span>
</span><span id="line-30"></span><span class="hs-comment">-----------------------------------------------------------------------------</span><span>
</span><span id="line-31"></span><span>
</span><span id="line-32"></span><span class="hs-keyword">module</span><span> </span><span class="hs-identifier">GHC.ExecutionStack</span><span> </span><span class="hs-special">(</span><span>
</span><span id="line-33"></span><span>    </span><span class="annot"><a href="GHC.ExecutionStack.Internal.html#Location"><span class="hs-identifier">Location</span></a></span><span> </span><span class="hs-special">(</span><span class="hs-glyph">..</span><span class="hs-special">)</span><span>
</span><span id="line-34"></span><span>  </span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.ExecutionStack.Internal.html#SrcLoc"><span class="hs-identifier">SrcLoc</span></a></span><span> </span><span class="hs-special">(</span><span class="hs-glyph">..</span><span class="hs-special">)</span><span>
</span><span id="line-35"></span><span>  </span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.ExecutionStack.html#getStackTrace"><span class="hs-identifier">getStackTrace</span></a></span><span>
</span><span id="line-36"></span><span>  </span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.ExecutionStack.html#showStackTrace"><span class="hs-identifier">showStackTrace</span></a></span><span>
</span><span id="line-37"></span><span>  </span><span class="hs-special">)</span><span> </span><span class="hs-keyword">where</span><span>
</span><span id="line-38"></span><span>
</span><span id="line-39"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="Control.Monad.html"><span class="hs-identifier">Control.Monad</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Base.html#join"><span class="hs-identifier">join</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-40"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.ExecutionStack.Internal.html"><span class="hs-identifier">GHC.ExecutionStack.Internal</span></a></span><span>
</span><span id="line-41"></span><span>
</span><span id="line-42"></span><span class="hs-comment">-- | Get a trace of the current execution stack state.</span><span>
</span><span id="line-43"></span><span class="hs-comment">--</span><span>
</span><span id="line-44"></span><span class="hs-comment">-- Returns @Nothing@ if stack trace support isn't available on host machine.</span><span>
</span><span id="line-45"></span><span class="annot"><a href="GHC.ExecutionStack.html#getStackTrace"><span class="hs-identifier hs-type">getStackTrace</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Maybe.html#Maybe"><span class="hs-identifier hs-type">Maybe</span></a></span><span> </span><span class="hs-special">[</span><span class="annot"><a href="GHC.ExecutionStack.Internal.html#Location"><span class="hs-identifier hs-type">Location</span></a></span><span class="hs-special">]</span><span class="hs-special">)</span><span>
</span><span id="line-46"></span><span id="getStackTrace"><span class="annot"><span class="annottext">getStackTrace :: IO (Maybe [Location])
</span><a href="GHC.ExecutionStack.html#getStackTrace"><span class="hs-identifier hs-var hs-var">getStackTrace</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Maybe (Maybe [Location]) -&gt; Maybe [Location]
forall (m :: * -&gt; *) a. Monad m =&gt; m (m a) -&gt; m a
</span><a href="GHC.Base.html#join"><span class="hs-identifier hs-var">join</span></a></span><span> </span><span class="annot"><span class="annottext">(Maybe (Maybe [Location]) -&gt; Maybe [Location])
-&gt; (Maybe StackTrace -&gt; Maybe (Maybe [Location]))
-&gt; Maybe StackTrace
-&gt; Maybe [Location]
forall b c a. (b -&gt; c) -&gt; (a -&gt; b) -&gt; a -&gt; c
</span><a href="GHC.Base.html#."><span class="hs-operator hs-var">.</span></a></span><span> </span><span class="annot"><span class="annottext">(StackTrace -&gt; Maybe [Location])
-&gt; Maybe StackTrace -&gt; Maybe (Maybe [Location])
forall (f :: * -&gt; *) a b. Functor f =&gt; (a -&gt; b) -&gt; f a -&gt; f b
</span><a href="GHC.Base.html#fmap"><span class="hs-identifier hs-var">fmap</span></a></span><span> </span><span class="annot"><span class="annottext">StackTrace -&gt; Maybe [Location]
</span><a href="GHC.ExecutionStack.Internal.html#stackFrames"><span class="hs-identifier hs-var">stackFrames</span></a></span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">(Maybe StackTrace -&gt; Maybe [Location])
-&gt; IO (Maybe StackTrace) -&gt; IO (Maybe [Location])
forall (f :: * -&gt; *) a b. Functor f =&gt; (a -&gt; b) -&gt; f a -&gt; f b
</span><a href="GHC.Base.html#fmap"><span class="hs-operator hs-var">`fmap`</span></a></span><span> </span><span class="annot"><span class="annottext">IO (Maybe StackTrace)
</span><a href="GHC.ExecutionStack.Internal.html#collectStackTrace"><span class="hs-identifier hs-var">collectStackTrace</span></a></span><span>
</span><span id="line-47"></span><span>
</span><span id="line-48"></span><span class="hs-comment">-- | Get a string representation of the current execution stack state.</span><span>
</span><span id="line-49"></span><span class="annot"><a href="GHC.ExecutionStack.html#showStackTrace"><span class="hs-identifier hs-type">showStackTrace</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Maybe.html#Maybe"><span class="hs-identifier hs-type">Maybe</span></a></span><span> </span><span class="annot"><a href="GHC.Base.html#String"><span class="hs-identifier hs-type">String</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-50"></span><span id="showStackTrace"><span class="annot"><span class="annottext">showStackTrace :: IO (Maybe String)
</span><a href="GHC.ExecutionStack.html#showStackTrace"><span class="hs-identifier hs-var hs-var">showStackTrace</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">([Location] -&gt; String) -&gt; Maybe [Location] -&gt; Maybe String
forall (f :: * -&gt; *) a b. Functor f =&gt; (a -&gt; b) -&gt; f a -&gt; f b
</span><a href="GHC.Base.html#fmap"><span class="hs-identifier hs-var">fmap</span></a></span><span> </span><span class="hs-special">(</span><span class="hs-glyph">\</span><span id="local-6989586621679566919"><span class="annot"><span class="annottext">[Location]
</span><a href="#local-6989586621679566919"><span class="hs-identifier hs-var">st</span></a></span></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="annottext">[Location] -&gt; ShowS
</span><a href="GHC.ExecutionStack.Internal.html#showStackFrames"><span class="hs-identifier hs-var">showStackFrames</span></a></span><span> </span><span class="annot"><span class="annottext">[Location]
</span><a href="#local-6989586621679566919"><span class="hs-identifier hs-var">st</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot;&quot;</span></span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">(Maybe [Location] -&gt; Maybe String)
-&gt; IO (Maybe [Location]) -&gt; IO (Maybe String)
forall (f :: * -&gt; *) a b. Functor f =&gt; (a -&gt; b) -&gt; f a -&gt; f b
</span><a href="GHC.Base.html#fmap"><span class="hs-operator hs-var">`fmap`</span></a></span><span> </span><span class="annot"><span class="annottext">IO (Maybe [Location])
</span><a href="GHC.ExecutionStack.html#getStackTrace"><span class="hs-identifier hs-var">getStackTrace</span></a></span><span>
</span><span id="line-51"></span></pre></body></html>